const fs = require('fs')
const path = require('path')

const createWriterStream = (fileName) => {
  const logPath = path.join(__dirname, `../../logs/`, fileName) // access.log or error.log
  return fs.createWriteStream(logPath, { flags: 'a' }) // "a" => append插入
}

const writeLog = (writeStream, logContent) => {
  writeStream.write(logContent + '\n') // 写入文件，并换行
}

const accessLog = (logContent) => {
  const writeStream = createWriterStream('access.log')
  writeLog(writeStream, logContent)
}

module.exports = {
  accessLog,
}
